package com.osgix.demo.mvc.controller;

import java.util.Locale;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.support.RequestContextUtils;

import com.osgix.authorize.model.UserInfo;
import com.osgix.authorize.service.UserInfoManager;
import com.osgix.common.mvc.AbsRedirectController;

@Controller
@RequestMapping("/index.htm")
public class IndexController extends AbsRedirectController {
	private static final Logger logger = Logger.getLogger(IndexController.class);

	@Resource
	private UserInfoManager userInfoManager;

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.setHeader("Pragma", "No-cache");
		response.setDateHeader("Expires", 0);
		response.setHeader("Cache-Control", "no-cache");

		Locale locale = RequestContextUtils.getLocale(request);

		if (logger.isInfoEnabled()) {
			logger.info(" locale is " + locale.toString());
		}

		UserInfo user = userInfoManager.getById(35L);

		ModelAndView mav = new ModelAndView("index");
		mav.addObject("locale", locale.toString());
		mav.addObject("user", user);
		return mav;
	}

	public void afterPropertiesSet() throws Exception {
		// TODO Auto-generated method stub
	}
}
